$(function () {
    $("#jqGrid").Grid({
        url: '../deviceinfo/listPlanRelated',
        sortname: 'CREATE_DATE',
        sortorder: 'DESC',
        rownumWidth: 35,
        height: 500,
        colModel: [
            {label: '设备编码', name: 'devCode', index: 'DEV_CODE', width: 70},
            {label: '设备名称', name: 'devName', index: 'DEV_NAME', width: 80},
            {label: '产线',
                formatter:function(value, col, row){
                    return row.devProductCode + ' ' + row.devProductName;
                }
            },
            {label: '工序',
                formatter:function(value, col, row){
                    return row.devProceNo + ' ' + row.devProceName;
                }
            },
            {label: '供应厂家名称', name: 'devSupplyName', index: 'devSupplyName', width: 80},
            {label: '设备状态', name: 'devStatus', index: 'DEV_STATUS', width: 60,
                formatter:function(v){
                    return sysEnums.STATUS[v];
                }
            }
        ]
    });
    vm.getTreeList();
    vm.getStore();
    vm.query();
});
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "deptId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url: "nourl"
        }
    },
    callback: {
        beforeCheck: true
    }

};
//部门树
var deptSetting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "deptId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url: "nourl",
            name:"complexName"
        }
    },
    callback: {
        beforeCheck: true,
        beforeClick: outTreeCheck
    }
};

function outTreeCheck(e, treeObj, treeNode) {
    vm.q.deptCode = treeObj.deptId;
    vm.query();
}

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            devCode: '',
            devName: '',
            devSupply: '',// 供应厂商编码
            devSupplyName: '',// 供应厂商名称
            deptCode:'', // 设备组织ID
            editStatus: 1 // 编制状态，默认为已编制
        },
        facType:'', //厂家名称
        planEditStatusList: enumsToList("PLAN_EDIT_STATUS"), // 设备计划编制状态
        showCheck: true,
        treeList:[] // 设备组织树列表
    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                search: true,
                postData: {
                    'devCode': vm.q.devCode,
                    'devName': vm.q.devName,
                    'deptCode': vm.q.deptCode,
                    'devSupply': vm.q.devSupply,
                    'devSupplyName': vm.q.devSupplyName,
                    'editStatus': vm.q.editStatus
                },
                page: page
            }).trigger("reloadGrid", [{ page: 1}]);
        },
        reloadSearch: function () {
            vm.q = {
                devCode: '',
                devName: '',
                devSupply: '',// 供应厂商编码
                devSupplyName: '',// 供应厂商名称
                deptCode:'', // 设备组织ID
                editStatus: 1 // 编制状态，默认为已编制
            };
            vm.reload();
        },
        getTreeList: function () {
            Ajax.request({
                url: '../sys/user/treeDeptBySCX',
                async: false,
                successCallback: function (r) {
                    vm.treeList = r.list;
                }
            });
        },
        //加载列表页树
        getStore: function () {
            deptZtree = $.fn.zTree.init($("#storeTree"), deptSetting, vm.treeList);
            deptZtree.expandAll(true);
        }
    }
});
